package com.thinkcube.edutainment;

import java.text.DecimalFormat;

import android.content.Context;
import android.util.DisplayMetrics;
import android.view.ViewGroup.MarginLayoutParams;
import android.widget.Gallery;

/**
 * MesithW @Cyberlmj
 * 3:57:14 PM 
 * Email: shanuka.gayashan@cyberlmj.com
 */
public class Util {
	
	public static float pixelsToSp(Context context, int px) {
	    float scaledDensity = context.getResources().getDisplayMetrics().scaledDensity;
	    return px/scaledDensity;
	}

	
	public static void setHomeGallry(Gallery galley,int dip,DisplayMetrics metrics)
	{
		MarginLayoutParams gallerylm = (MarginLayoutParams) galley.getLayoutParams();
		gallerylm.setMargins(-(metrics.widthPixels/2+75*dip), 
				gallerylm.topMargin, 
				gallerylm.rightMargin, 
				gallerylm.bottomMargin
				
        );
	}
	
	
	public static String numberFormat(String number){
	    boolean mustFormat = true;
	    String formattedvalue = "";		    
	    try{
		    if(number!= null){
		    	
		    String character = "[.]";
			String a[] = number.split(character);

			if (a != null) {
				if (a.length > 1) {
					if (a[1].length() > 2) {
						formattedvalue = a[0] + "." + a[1].substring(0, 2);
					} else {
						formattedvalue = number;
					}
				} else {
					formattedvalue = number;

				}
			}
		 
			if(mustFormat){
		
					double amount = Double.parseDouble(formattedvalue);
			        DecimalFormat formatter = new DecimalFormat("#,###.00");
			        formattedvalue =formatter.format(amount);

			}
			
		    }
	    }catch(Exception e){
	        formattedvalue = "";
        }
        return formattedvalue;
 }
}
